<template>
  <div class="form">
    <el-form
      :label-width="props.labelWidth"
      size="small"
      ref="form"
    >
      <slot></slot>

      <el-collapse-transition>
        <div v-show="state.collapse">
          <slot name="hidden"></slot>
        </div>
      </el-collapse-transition>
      <slot name="fixed"></slot>
    </el-form>

    <div>
      <el-button
        :icon="Search"
        type="primary"
        @click="submit"
        size="small"
        >查询</el-button
      >
      <el-button v-show="!props.hideClean" class="clean" @click="reset"
        >清空</el-button
      >
      <el-button
        type="primary"
        v-show="hasHiddenContent"
        @click="state.collapse = !state.collapse"
      >
        <el-icon style="transform: rotate(90deg)">
          <MoreFilled />
        </el-icon>
        {{ state.collapse ? "折叠" : "更多条件" }}
        <i
          class="el-icon-arrow-down collapse"
          :class="state.collapse ? 'rotate' : ''"
        ></i>
      </el-button>
    </div>
  </div>
</template>

<script setup>
import {
  ref,
  onMounted,
  defineEmits,
  defineProps,
  reactive,
  useSlots,
  computed,
} from "vue";
import { Search,MoreFilled } from "@element-plus/icons-vue";

const props = defineProps({
  // 隐藏 清除筛选条件
  hideClean: {
    type: Boolean,
    default: false,
  },
  // 在清空筛选条件后提交
  submitAfterReset: {
    type: Boolean,
    default: false,
  },
  labelWidth: {
    type: String,
    default: "100px",
  },
});

const emit = defineEmits(["submit", "reset"]);

const myslot = useSlots();

const state = reactive({
  collapse: false,
});

const submit = () => {
  emit("submit");
};
const reset = () => {
  emit("reset");
  if (props.submitAfterReset) {
    emit("submit");
  }
};

const hasHiddenContent = computed(() => {
  if (!myslot.hidden) {
    return false;
  }
  console.log("hidden", myslot.hidden);
  let slot = myslot.hidden();
  if (!slot) {
    return false;
  }
  if (slot.length != 0) {
    return true;
  }
  return false;
});
</script>

<style lang="scss" scoped>
.form {
  padding: 12px;
  background-color: #FFFFFF;
}
.clean {
  margin-left: 15px;
}
.collapse {
  transition: all 0.5s ease;
}
.rotate {
  // transition: all 0.5s ease;
  transform: rotate(-180deg);
}

:deep(.el-form-item--small){
  margin-bottom: 8px;
}
</style>
